The GAWK Manual

Edition 0.14 November 1992

Diane Barlow Close Arnold D. Robbins Paul H. Rubin Richard Stallman

Copyright \begin{matrix}c \\ ◯ \end{matrix} 1989, 1991, 1992 Free Software Foundation, Inc.

This is Edition 0.14 of The GAWK Manual, for the 2.14 version of the GNU implementation of AWK.

Published by the Free Software Foundation 675 Massachusetts Avenue Cambridge, MA 02139 USA Printed copies are available for $15 each.

Permission is granted to make and distribute verbatim copies of this manual provided the copyright notice and this permission notice are preserved on all copies.

Permission is granted to copy and distribute modified versions of this manual under the conditions for verbatim copying, provided that the entire resulting derived work is distributed under the terms of a permission notice identical to this one.

Permission is granted to copy and distribute translations of this manual into another language, under the above conditions for modified versions, except that this permission notice may be stated in a translation approved by the Foundation.

Preface

If you are like many computer users, you would frequently like to make changes in various text files wherever certain patterns appear, or extract data from parts of certain lines while discarding the rest. To write a program to do this in a language such as C or Pascal is a time-consuming inconvenience that may take many lines of code. The job may be easier with awk.

The awk utility interprets a special-purpose programming language that makes it possible to handle simple data-reformatting jobs easily with just a few lines of code.

The GNU implementation of awk is called gawk; it is fully upward compatible with the System V Release 4 version of awk. gawk is also upward compatible with the posix (draft) specification of the awk language. This means that all properly written awk programs should work with gawk. Thus, we usually don’t distinguish between gawk and other awk implementations in this manual.

This manual teaches you what awk does and how you can use awk effectively. You should already be familiar with basic system commands such as ls. Using awk you can:

• manage small, personal databases

• generate reports

• validate data

• produce indexes, and perform other document preparation tasks

• even experiment with algorithms that can be adapted later to other computer languages

This manual has the difficult task of being both tutorial and reference. If you are a novice, feel free to skip over details that seem too complex. You should also ignore the many cross references; they are for the expert user, and for the on-line Info version of the manual.

History of awk and gawk

The name awk comes from the initials of its designers: Alfred V. Aho, Peter J. Weinberger, and Brian W. Kernighan. The original version of awk was written in 1977. In 1985 a new version made the programming language more powerful, introducing user-defined functions, multiple input streams, and